/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.portalnahouby.implementation.serviceimplementation;

import cz.muni.fi.pa165.portalnahouby.api.dto.ForestDTO;
import cz.muni.fi.pa165.portalnahouby.api.dto.VisitDTO;
import cz.muni.fi.pa165.portalnahouby.api.serviceinterface.VisitService;
import cz.muni.fi.pa165.portalnahouby.implementation.daointerface.VisitDAO;
import cz.muni.fi.pa165.portalnahouby.implementation.entity.Visit;
import cz.muni.fi.pa165.portalnahouby.implementation.util.EntityDTOConvertor;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Implementation of visit service
 * 
 * @author Filip Kiss
 */
@Service
public class VisitServiceImpl implements VisitService {

	@Autowired
	private VisitDAO visitDAO;

	public void setVisitDAO(VisitDAO visitDAO) {
		this.visitDAO = visitDAO;
	}

	@Override
	public void addVisit(VisitDTO visit) {
                Visit visitEntity = EntityDTOConvertor.convertVisit(visit);
		visitDAO.addVisit(visitEntity);
		visit.setId(visitEntity.getId());
	}

	@Override
	public void editVisit(VisitDTO visit) {
            visitDAO.editVisit(EntityDTOConvertor.convertVisit(visit));
        }

	@Override
	public void deleteVisit(Long id) {
            visitDAO.deleteVisit(id);
        }

	@Override
	public VisitDTO findVisit(Long id) {
		return EntityDTOConvertor.convertVisit(visitDAO.findVisit(id));
	}

	@Override
	public List<VisitDTO> getAllVisits() {
		List<Visit> entityVisits = visitDAO.getAllVisits();
                List<VisitDTO> dtoVisits = new ArrayList<VisitDTO>();
                for (Visit visit : entityVisits){
                    dtoVisits.add(EntityDTOConvertor.convertVisit(visit));
                }
                return dtoVisits;
	}

	@Override
	public List<VisitDTO> getListOfForestByDate(ForestDTO forest) {
                List<Visit> entityVisits = visitDAO.getListOfForestByDate(EntityDTOConvertor.convertForest(forest));
                List<VisitDTO> dtoVisits = new ArrayList<VisitDTO>();
                for (Visit visit : entityVisits){
                    dtoVisits.add(EntityDTOConvertor.convertVisit(visit));
                }
                return dtoVisits;
        }

	@Override
	public List<VisitDTO> getListOfForestByPicker(ForestDTO forest) {
		List<Visit> entityVisits = visitDAO.getListOfForestByPicker(EntityDTOConvertor.convertForest(forest));
                List<VisitDTO> dtoVisits = new ArrayList<VisitDTO>();
                for (Visit visit : entityVisits){
                    dtoVisits.add(EntityDTOConvertor.convertVisit(visit));
                }
                return dtoVisits;
	}

	@Override
	public List<VisitDTO> getListByForest() {
		List<Visit> entityVisits = visitDAO.getListByForest();
                List<VisitDTO> dtoVisits = new ArrayList<VisitDTO>();
                for (Visit visit : entityVisits){
                    dtoVisits.add(EntityDTOConvertor.convertVisit(visit));
                }
                return dtoVisits;
	}
}
